﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EdgeSearch.Core.SqlSugar
{
    /// <summary>
    /// SqlSugar 实体仓储
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class SqlSugarRepository<T> : SimpleClient<T> where T : class, new()
    {
        public SqlSugarRepository()
        {
            var iTenant = SqlSugarSetup.ITenant;
            base.Context = iTenant.GetConnectionScope(SqlSugarConst.MainConfigId);

            // 若实体贴有多库特性，则返回指定库连接
            if (typeof(T).IsDefined(typeof(TenantAttribute), false))
            {
                base.Context = iTenant.GetConnectionScopeWithAttr<T>();
                return;
            }
            return;
        }
    }
}
